#pragma once

#include "BlendState.hpp"
#include "D3D11Declarations.hpp"
#include "D3D11DeviceContext.hpp"




namespace Engine
{
	namespace Video
	{
		class D3D11BlendState
			: public BlendState
		{
		public:

			SHARED(D3D11BlendState);
			typedef boost::function<void (weak_ptr)>   notify;

		protected:

			D3D11BlendState(const notify& destroyedFn);
			void post_create(ptr _this);

		public:

			MAKE_SHARED1(D3D11BlendState,notify);
			~D3D11BlendState();



			/**
			 * Define the first RGB data source.
			 */
			void setSrcBlend(Blend::Type blend);

			/**
			 * Defines the second RGB data source.
			 */
			void setDestBlend(Blend::Type blend);

			/**
			 * Defines the blending operation that is given both data sources.
			 */
			void setBlendOp(BlendOp::Type blendOp);



			const ID3D11BlendStatePtr& apply(const ID3D11DevicePtr& device, D3D11DeviceContext& context);

		private:

			void update(const ID3D11DevicePtr& device, D3D11DeviceContext& context);

			static D3D11_BLEND fromBlend(Blend::Type blend);
			static D3D11_BLEND_OP fromBlendOp(BlendOp::Type blendOp);

		private:

			weak_ptr              m_this;
			bool                  m_changed;
			notify                m_destroyed;

			Blend::Type           m_srcBlend;
			Blend::Type           m_destBlend;
			BlendOp::Type         m_blendOp;

			ID3D11BlendStatePtr   m_blendState;
		};
		///////////////////////////////////////////////////////////////////////////////////////////
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
